// pages/login/login.js
let app = getApp();

Page({

  data: {
    username:[],
    passWord:[]
  },
  adddetial: function () {
    wx.navigateTo({
      url: '/pages/post/post',
      success: function (res) { },
      fail: function (res) { },
      complete: function (res) { },
    })
  },
  onLoad: function (options) {
  },

  IdInput:function(e){
    this.setData({
      username : e.detail.value
    })
  },

  PswInput:function(e){
    this.setData({
      passWord : e.detail.value
    })
  },

  login:function(){
    wx.request({
      url: 'https://www.woodymidnight.cn/BCUHelper/api/user/selectUserByUserName',  
      method: 'GET',
      data:{
        password : this.data.passWord,
        userName : this.data.username
      },                                      
      header: { 'content-type': 'application/x-www-form-urlencoded' },
      success :( e) => {
        if(e.data.data[0] == null){
          this.setData({
            passWord : ''
          })
          wx.showToast({
            title: '账户或密码错误',
            icon: 'error',
            mask: true
          })
        }else{
          app.data.userInfo = e.data.data[0]
          wx.switchTab({
            url: '../index/index',
          })
        }
      }
    })
  }

})